using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Gencode.Common.SQL;

namespace Personalplaner
{
    public partial class OldYearDlg : Form
    {
        int year = 0;

        public OldYearDlg()
        {
            InitializeComponent();
            setComboYear();
        }

        private void setComboYear()
        {
			DataView dv = SimpleQuerry.ExecuteForDataView("select jahr from planungsjahr where status > 1");
            for (int i = 0; i < dv.Count; i++)
            {
                comboJear.Items.Add(dv[i].Row[0].ToString());
            }
        }

        public int getYear()
        {
            return year;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void comboJear_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboJear.SelectedIndex >= 0)
            {
                btnOldYear.Enabled = true;
            }
        }

        private void btnOldYear_Click(object sender, EventArgs e)
        {
            if (comboJear.Text != "")
            {
                try
                {
                    year = Int32.Parse(comboJear.Text);
                }
                catch (Exception exp)
                {
                    //MessageBox.Show(exp.Message);
					Gencode.Common.Util.ErrorHandler.LoggError("OldYear Error", "OldYearDlg.btnOldYear_Click", exp.Message);
                }

                updateYear();

                DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void updateYear()
        {
			Querry stp = new Querry();
            stp.SetSTPName("upd_planungsjahr_jahr");

            stp.AddParameter("@jahr", year);

            stp.Execute();
        }
    }
}